package frsf.cidisi.exercise.laberinto.search.actions;

import frsf.cidisi.exercise.laberinto.search.EstadoAgente;
import frsf.cidisi.exercise.laberinto.search.EstadoLaberinto;
import frsf.cidisi.exercise.laberinto.search.util.Orientacion;
import frsf.cidisi.faia.agent.search.SearchAction;
import frsf.cidisi.faia.agent.search.SearchBasedAgentState;
import frsf.cidisi.faia.state.AgentState;
import frsf.cidisi.faia.state.EnvironmentState;

public class GirarDerecha extends SearchAction {

    /**
     * This method updates a tree node state when the search process is running.
     * It does not updates the real world state.
     */
    @Override
    public SearchBasedAgentState execute(SearchBasedAgentState s) {
        EstadoAgente agState = (EstadoAgente) s;
        Orientacion o = agState.getOrientacion().girarDerecha();
        agState.setOrientacion(o);
        return agState;
    }

    /**
     * This method updates the agent state and the real world state.
     */
    @Override
    public EnvironmentState execute(AgentState ast, EnvironmentState est) {
        EstadoLaberinto environmentState = (EstadoLaberinto) est;
        EstadoAgente agState = ((EstadoAgente) ast);
        Orientacion o = agState.getOrientacion().girarDerecha();
        agState.setOrientacion(o);
        return environmentState;
    }

    /**
     * This method returns the action cost.
     */
    @Override
    public Double getCost() {
        return new Double(3);
    }

    /**
     * This method is not important for a search based agent, but is essensial
     * when creating a calculus based one.
     */
    @Override
    public String toString() {
        return "GirarDerecha";
    }
}